package com.example.recyclerviewtest;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.recyclerviewtest.databinding.RecyclerviewItemBinding;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class recy_item_Adapter extends RecyclerView.Adapter<recy_item_Adapter.ViewHolder> {
    public List<Map<String,Object>> list=new ArrayList<>();
    //public Context context;
    private RecyclerviewItemBinding binding;
    public  recy_item_Adapter(List<Map<String,Object>> list){
        //this.context=context;
        this.list=list;
    }
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        binding = RecyclerviewItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new ViewHolder(binding);

    }
    @NonNull
    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        Map<String, Object> item = list.get(position);
        holder.binding.sortTitle.setText((String) item.get("sortTitle"));
        holder.binding.countryRegionName.setText((String) item.get("countryRegionName"));
        holder.binding.areaCode.setText((String) item.get("areaCode"));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        RecyclerviewItemBinding binding;
        public TextView recy_tv;
        public ViewHolder(@NonNull RecyclerviewItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
